/*
 * @Description: 用户模块接口
 * @Author: Yong
 * @Date: 2021-09-27 11:48:54
 * @LastEditTime: 2021-09-27 21:50:30
 */
import { Http } from '../utils'

const API = {
    login: '/user/login',
    logout: '/user/logout',
    getUserInfo: '/user',
    getFavorites: '/user/favorites',
    houses: '/user/houses',
}

/**
 * 用户登录
 * @param data { username: '', password: '' }
 */
export const login = function (data) {
    return Http('post', API.login, data)
}

/**
 * 用户退出登录 - 需要在请求头携带token信息 authorization: token
 * @param
 */
 export const logout = function () {
    return Http('post', API.logout)
}

/**
 * 获取用户信息 - 需要在请求头携带token信息 authorization: token
 */
export const getUserInfo = function () {
    return Http('get', API.getUserInfo)
}


/**
 * 根据ID获取用户是否收藏房源
 */
export const getFavorites = function (id) {
    return Http('get', `${API.getFavorites}/${id}`)
}

/**
 * 添加房源收藏
 */
export const addFavorites = function (id) {
    return Http('post', `${API.getFavorites}/${id}`)
}

/**
 * 删除房源收藏
 */
export const deleteFavorites = function (id) {
    return Http('delete', `${API.getFavorites}/${id}`)
}

/**
 * 获取用户已发布房源列表
 */
export const getPublicHouses = function () {
    return Http('get', `${API.houses}`)
}

/**
 * 用户发布房源
 */
export const addHouse = function (params) {
     return Http('post', `${API.houses}`, params)
}